package com.cqw.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-08 14:46
 * @Description:
 */
@Service
@Slf4j
public class ThreadService {


    /**
     * 无返回值
     */
    @Async("executorPool")
    public void test1() {
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("我是test1的结果");
    }


    /**
     * 有返回值
     */
    @Async("executorPool")
    public CompletableFuture<String> test2() {
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("我是test2的结果");

        return CompletableFuture.completedFuture("Test2");
    }
}
